package com.project.smarthome.common.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

/**
 * Created by liweiyong on 2015/10/8.
 */
public class HeightListView extends ListView {

    /**
     * listview高度
     */
    private int mListViewHeight;

    public int getmListViewHeight() {
        return mListViewHeight;
    }

    public void setmListViewHeight(int mListViewHeight) {
        this.mListViewHeight = mListViewHeight;
    }

    public HeightListView(Context context) {
        super(context);
    }

    public HeightListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public HeightListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    /**
     * 重写该方法，达到使ListView适应ScrollView的效果
     */
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // TODO Auto-generated method stub
        if (mListViewHeight > -1) {
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(mListViewHeight,
                    MeasureSpec.AT_MOST);
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

}
